package system.student.funtion.exhibition.adminfunction.impl;

import system.student.entity.Clazz;
import system.student.funtion.exhibition.adminfunction.ClazzService;
import system.student.mapper.ClazzMapper;
import system.student.util.MapperUtil;

import java.util.List;

public class ClazzServiceImpl implements ClazzService {

    private ClazzMapper clazzMapper = MapperUtil.getMapper(ClazzMapper.class);

    @Override
    public void addClazz(String classname, Long teacherId) {
        String className = clazzMapper.selectByClassName(classname);
        if (className != null) {
            System.out.println("该班级已存在");
            return;
        }
        String teacherName = clazzMapper.selectByTeacherId(teacherId);
        if (teacherName == null) {
            System.out.println("该老师不存在");
            return;
        }
        clazzMapper.addClazz(classname, teacherId);
        System.out.println("添加成功");
    }

    @Override
    public void deleteClazz(String classname) {
        if (clazzMapper.selectByClassName(classname) == null) {
            System.out.println("该班级不存在");
            return;
        }
        clazzMapper.deleteClazz(classname);
    }

    @Override
    public List<Clazz> selectAllClazz() {

        List<Clazz> clazzes = clazzMapper.selectAllClazz();
        if (clazzes.size() == 0) {
            System.out.println("暂时没有班级");
        }
        return clazzes;
    }

    @Override
    public void changeClazz(Long clazzId, String classname, Long teacherId) {
        String className = clazzMapper.selectByClassName(classname);
        if (className != null) {
            System.out.println("该班级已存在");
            return;
        }
        String teacherName = clazzMapper.selectByTeacherId(teacherId);
        if (teacherName == null) {
            System.out.println("该老师不存在");
            return;
        }
        clazzMapper.changeClazz(clazzId, classname, teacherId);
        System.out.println("修改成功");
    }
}
